package migrations

import (
	"database/sql"

	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models"
	"gitee.com/sweetsunnyflower/carpooling-server-go/pkg/migrate"

	"gorm.io/gorm"
)

func init() {

	type User struct {
		models.BaseModel

		OpenId   string `gorm:"type:varchar(255);comment:微信openid;not null;index"`
		Name     string `gorm:"type:varchar(255);comment:用户昵称;not null;index"`
		Avatar   string `gorm:"type:varchar(255);comment:用户头像;not null;"`
		Email    string `gorm:"type:varchar(255);comment:邮箱;index;default:null"`
		Phone    string `gorm:"type:varchar(20);comment:手机号;index;default:null"`
		Gender   uint8  `gorm:"comment:性别 2:女,1:男;default:0;" db:"gender" json:"gender" form:"gender"`
		Password string `gorm:"type:varchar(255)"`

		models.CommonTimestampsField
	}

	up := func(migrator gorm.Migrator, DB *sql.DB) {
		migrator.AutoMigrate(&User{})
	}

	down := func(migrator gorm.Migrator, DB *sql.DB) {
		migrator.DropTable(&User{})
	}

	migrate.Add("2023_07_15_223634_add_users_table", up, down)
}
